<?php

namespace Tasker\Configurator;

/**
 * @property-read \Tasker\Models\CalendarModel $calendar
 * @property-read \Tasker\Models\ProjectModel $project
 * @property-read \Tasker\Models\ProjectsModel $projects
 * @property-read \Tasker\Models\TaskModel $task
 * @property-read \Tasker\Models\TasksModel $tasks
 * @property-read \Tasker\Models\UsersModel $users
 * @property-read \Tasker\Models\FilesModel $files
 * @property-read \Tasker\Models\StatusModel $status
 * @property-read \Tasker\Models\TaskContextModel $taskContext
 * @property-read \Tasker\Models\DepartmentModel $department
 * @property-read \Tasker\Models\AuthorizationModel $authorization
 */
class ModelsLocator extends \Nette\DI\Container
{

	protected $namespace = '\\Tasker\\Models\\';
	protected $services = array(
		'calendar' => 'CalendarModel',
		'project' => 'ProjectModel',
		'projects' => 'ProjectsModel',
		'task' => 'TaskModel',
		'tasks' => 'TasksModel',
		'users' => 'UsersModel',
		'files' => 'FilesModel',
		'status' => 'StatusModel',
		'taskContext' => 'TaskContextModel',
		'department' => 'DepartmentModel',
		'authorization' => 'AuthorizationModel',
	);

	public function __construct(\Nette\DI\Container $container)
	{
		$this->addService('container', $container);
		foreach ($this->services as $name => $class)
		{
			$classname = $this->namespace . $class;
			if (class_exists($classname))
			{
				if ($class == 'UsersModel')
				{
					$this->addService($name, new $classname($this->container->connection, $this->container->authenticator));
				} else
				{
					$this->addService($name, new $classname($this->container->connection));
				}
			}
		}
	}

}
